#include "Components/AutoShape/AutoShapeComponent.h"
#include "Components/AutoShape/AutoShapeConfigBase.h"

UAutoShapeComponent::UAutoShapeComponent(const FObjectInitializer& ObjectInitializer)
{
	ShapeColor = FColor(255, 0, 0, 255);
	bUseEditorCompositing = true;
}

FPrimitiveSceneProxy* UAutoShapeComponent::CreateSceneProxy()
{
	return ShapeConfig ? ShapeConfig->CreateSceneProxy(this) : UPrimitiveComponent::CreateSceneProxy();
}

bool UAutoShapeComponent::IsZeroExtent() const
{
	return ShapeConfig ? ShapeConfig->IsZeroExtent(this) : UPrimitiveComponent::IsZeroExtent();
}

struct FCollisionShape UAutoShapeComponent::GetCollisionShape(float Inflation) const
{
	return ShapeConfig ? ShapeConfig->GetCollisionShape(this, Inflation) : UPrimitiveComponent::GetCollisionShape(Inflation);
}

bool UAutoShapeComponent::AreSymmetricRotations(const FQuat& A, const FQuat& B, const FVector& Scale3D) const
{
	return ShapeConfig ? ShapeConfig->AreSymmetricRotations(this, A, B, Scale3D) : UPrimitiveComponent::AreSymmetricRotations(A, B, Scale3D);
}

FBoxSphereBounds UAutoShapeComponent::CalcBounds(const FTransform& LocalToWorld) const
{
	return ShapeConfig ? ShapeConfig->CalcBounds(this, LocalToWorld) : UPrimitiveComponent::CalcBounds(LocalToWorld);
}

void UAutoShapeComponent::CalcBoundingCylinder(float& CylinderRadius, float& CylinderHalfHeight) const
{
	ShapeConfig ? ShapeConfig->CalcBoundingCylinder(this, CylinderRadius, CylinderHalfHeight) : USceneComponent::CalcBoundingCylinder(CylinderRadius, CylinderHalfHeight);
}

void UAutoShapeComponent::UpdateBodySetup()
{
	// ShapeConfig ? ShapeConfig->UpdateBodySetup(this) : Super::UpdateBodySetup();
	if (ShapeConfig)
	{
		if (CastChecked<UAutoShapeComponent>(GetArchetype())->ShapeConfig != ShapeConfig)
		{
			SetbUseArchetypeBodySetup(false);
		}
		ShapeConfig->UpdateBodySetup(this);
	}
}
